const path = require('path');
// module.exports = {
//     alias: {
//         // @ 即为别名，你也可以更改为自己喜欢的别名 --->  import Nav from '/@/components/Nav.vue';
//         '/@/': path.resolve(__dirname, './src'),
//     },
//      // 反向代理
//      proxy: {
//         hostname: 'localhost',
//         port: 9999,
//         '/api': {
//             target: 'http://localhost:8085/',
//             changeOrigin: true,
//             rewrite: path => path.replace(/^\/api/, '')
//         }
//     }

// }

import { defineConfig, loadEnv } from "vite";
import vue from '@vitejs/plugin-vue'

export default defineConfig(({ mode }) => {
    const target = loadEnv(mode, process.cwd()).VITE_APP_BASE_URL;
    console.log({target});
    return {
        plugins: [vue()],
        resolve: {
            alias: [{
                find: '@',
                replacement: path.resolve(__dirname, 'src')
            },
            {
                find: 'components',
                replacement: path.resolve(__dirname, 'src/components')
            }
            ],

        },
        server: {//服务器配置
            port:3001,//端口
            open:true,//自动打开浏览器
            proxy: { //代理
                "/api": {
                    target:target,
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api/, ""),
                },
            },
        },
    }
});

